import router from './router'
import { Toast } from 'vant'
import config from "./sgApi/config.js"



function getUrlParam(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
  var r = window.location.search.substr(1).match(reg)
  if (r != null) return unescape(r[2])
  return null

}

const code = getUrlParam('code')
let local = window.location.href
if (code == null || code === '') {

  window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + config.appId + '&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'
} else {
  localStorage.setItem("code", code)
}





 



router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }

  //  判断是否在微信浏览器打开
  var ua = navigator.userAgent.toLowerCase();
  var isWeixin = ua.indexOf('micromessenger') != -1;
  if (!isWeixin) {
    window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=888"
  }

  next()

})